package com.ruoyi.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MedPre;
import com.ruoyi.system.service.IMedPreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 处方药品对应Controller
 * 
 * @author yangxp
 * @date 2020-07-31
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/medicine/medPre" )
public class MedPreController extends BaseController {

    private final IMedPreService iMedPreService;

    /**
     * 查询处方药品对应列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPre:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedPre medPre)
    {
        startPage();
        LambdaQueryWrapper<MedPre> lqw = new LambdaQueryWrapper<MedPre>();
        List<MedPre> list = iMedPreService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出处方药品对应列表
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPre:export')" )
    @Log(title = "处方药品对应" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MedPre medPre) {
        LambdaQueryWrapper<MedPre> lqw = new LambdaQueryWrapper<MedPre>(medPre);
        List<MedPre> list = iMedPreService.list(lqw);
        ExcelUtil<MedPre> util = new ExcelUtil<MedPre>(MedPre. class);
        return util.exportExcel(list, "medPre" );
    }

    /**
     * 获取处方药品对应详细信息
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPre:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMedPreService.getById(id));
    }

    /**
     * 新增处方药品对应
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPre:add')" )
    @Log(title = "处方药品对应" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedPre medPre) {
        return toAjax(iMedPreService.save(medPre) ? 1 : 0);
    }

    /**
     * 修改处方药品对应
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPre:edit')" )
    @Log(title = "处方药品对应" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedPre medPre) {
        return toAjax(iMedPreService.updateById(medPre) ? 1 : 0);
    }

    /**
     * 删除处方药品对应
     */
    @PreAuthorize("@ss.hasPermi('medicine:medPre:remove')" )
    @Log(title = "处方药品对应" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iMedPreService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
